package com.zmx.doctor.adapter;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.wang.adapters.adapter.BaseAdapterRvList;
import com.wang.adapters.base.BaseViewHolder;
import com.zmx.doctor.R;
import com.zmx.doctor.pojo.ArticleMessage;
import com.zmx.doctor.pojo.GoodsOrder;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GoodsOrderDetailsAdapter extends BaseAdapterRvList<GoodsOrderDetailsAdapter.ViewHolder, GoodsOrder> {

    private Handler handler;
    private Integer logo;

    public GoodsOrderDetailsAdapter(Activity activity,Handler handler,Integer logo) {
        super(activity);
        this.handler = handler;
        this.logo = logo;
    }

    @Override
    protected void onBindVH(ViewHolder holder, int listPosition, GoodsOrder goodsOrder) {


//        Glide.with(mActivity).load(goodsOrder.get).into(holder.image);

        holder.name.setText(goodsOrder.getGoods_name());
        holder.number.setText("x"+goodsOrder.getNumber());
        holder.price.setText("单价："+goodsOrder.getPrice()+"元");
        holder.yizu.setText(goodsOrder.getUsage());
        holder.total_money.setText("小计："+goodsOrder.getPrice()*goodsOrder.getNumber()+"元");

        if (logo == 0){

            holder.editor_button.setVisibility(View.GONE);
            holder.delete_button.setVisibility(View.GONE);

        }else{

            holder.editor_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Message message = handler.obtainMessage();
                message.what=3;
                message.arg1=listPosition;
                handler.sendMessage(message);


            }
        });

            holder.delete_button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    Message message = handler.obtainMessage();
                    message.what=4;
                    message.arg1=listPosition;
                    handler.sendMessage(message);

                }
            });


        }



    }

    @NonNull
    @Override
    protected ViewHolder onCreateVH(ViewGroup parent, LayoutInflater inflater) {

        GoodsOrderDetailsAdapter.ViewHolder holder = new GoodsOrderDetailsAdapter.ViewHolder(inflater.inflate(R.layout.adapter_goods_order_details, parent, false));
        return holder;

    }

    static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.number)
        TextView number;
        @BindView(R.id.yizu)
        TextView yizu;
        @BindView(R.id.price)
        TextView price;
        @BindView(R.id.total_money)
        TextView total_money;
        @BindView(R.id.delete_button)
        Button delete_button;
        @BindView(R.id.editor_button)
        Button editor_button;


        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

    }



}
